19
We do this with the set operation applied on instance k:
{ Precondition: Let k = n where n is any Integer }
k.set(i.add(j))
{ Postcondition: k = i + j }
Implementation of ADT:
Step 3: add (Cont.)
MODULAR PROGRAMMING
int i, j, k; /* Define three integers */
i = 1; /* Assign 1 to integer i */
j = 2; /* Assign 2 to integer j */
k = i + j; /* Assign the sum of i and j to k */
Consider the ADT Integer. Outline the relationship to the ADT Integer in the following code:
The postcondition ensures that i and j do not change their values. Please recall the specification of add. It says that a new Integer is created the value of which is the sum. Consequently, we must provide a mechanism to access this new instance.